package cc.cix.gt.org.controller;

import cc.cix.gt.org.dto.response.IndexResp;
import cc.cix.gt.org.entity.LoginLog;
import cc.cix.gt.org.service.ILoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cix
 */
@Api(tags = "首页管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/index")
public class IndexController {

    private final ILoginLogService loginLogService;

    @ApiOperation("首页")
    @GetMapping("/index")
    public IndexResp index() {
        // 获取总访问次数
        Long totalVisitCount = loginLogService.count();
        // 获取今日访问次数
        Long todayVisitCount = loginLogService.getTodayVisitCount();
        // 获取今日访问 IP 数
        Long todayIp = loginLogService.getTodayIp();
        // 获取近10天访问记录
        List<LoginLog> lastTenVisitCount = loginLogService.getLastTenVisitCount();
        // 获取近10天当前用户的访问记录
        List<LoginLog> lastTenUserVisitCount = loginLogService.getLastTenUserVisitCount();

        IndexResp indexVO = new IndexResp();
        indexVO.setTotalVisitCount(totalVisitCount);
        indexVO.setTodayVisitCount(todayVisitCount);
        indexVO.setTodayIp(todayIp);
        indexVO.setLastTenVisitCount(lastTenVisitCount);
        indexVO.setLastTenUserVisitCount(lastTenUserVisitCount);
        return indexVO;
    }

}
